import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Locale;

import org.junit.jupiter.api.Test;

/**
 * @author chenwenlong03 <chenwenlong03@kuaishou.com>
 * Created on 2021-11-24
 */
public class MyTest1 {

    @Test
    public void test() throws Exception {
        UserController userController = new UserController();
        Class<?> clazz = userController.getClass();
        // 创建对象
        UserService userService = new UserService();
        System.out.println(userService);
        // 获取所有的属性
        Field serviceField = clazz.getDeclaredField("userService");
        serviceField.setAccessible(true);
        String name = serviceField.getName();
        name = name.substring(0,1).toUpperCase()+name.substring(1,name.length());
        String setMethodName = "set" + name;
        Method method = clazz.getMethod(setMethodName, UserService.class);
        method.invoke(userController,userService);
        System.out.println(userController.getUserService());


    }
}
